package com.ruoyi.edh.mapper;

import com.ruoyi.edh.domain.EdhGoods;
import com.ruoyi.edh.domain.EdhGoodsDetail;
import com.ruoyi.edh.domain.dto.EdhSummaryGoodsDto;
import com.ruoyi.edh.domain.vo.EdhDetailsGoodsVo;
import com.ruoyi.edh.domain.vo.EdhSummaryGoodsListVo;
import com.ruoyi.edh.domain.vo.EdhSummaryGoodsVo;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.javassist.bytecode.annotation.LongMemberValue;

import java.util.List;
import java.util.Map;


/**
 * 易订货-商品Mapper接口
 *
 * @author xxx
 * @date 2020-09-02
 */
public interface EdhGoodsMapper
{
    /**
     * 查询易订货-商品
     *
     * @param id 易订货-商品ID
     * @return 易订货-商品
     */
    public EdhGoods selectEdhGoodsById(Long id);

    /**
     * 根据部分dto中的字段查询商品的概要信息
     * @param edhSummaryGoodsDto
     * @return
     */
    public List<EdhSummaryGoodsVo> selectSummaryGoodsList(EdhSummaryGoodsDto edhSummaryGoodsDto);
    /**
     *
     *
     * @description: 商品列表查询
     * @param edhGoods
     * @return:
     * @author: 梁东宸
     * @time: 2020/9/8 5:05 下午
     */
    public List<EdhSummaryGoodsListVo>queryEdhGoodsList(EdhGoods edhGoods);

    String seletDetailsByGoodsId(Long id);
    /**
     * 根据id查询商品的详情信息
     * @param id
     * @return
     */
    public EdhDetailsGoodsVo selectDetailsGoodsByid(String id);

    /**
     * 查询易订货-商品列表
     *
     * @param edhGoods 易订货-商品
     * @return 易订货-商品集合
     */
    public List<EdhGoods> selectEdhGoodsList(EdhGoods edhGoods);

    /**
     * 新增易订货-商品
     *
     * @param edhGoods 易订货-商品
     * @return 结果
     */
    public int insertEdhGoods(EdhGoods edhGoods);

    /**
     * 修改易订货-商品
     *
     * @param edhGoods 易订货-商品
     * @return 结果
     */
    public int updateEdhGoods(EdhGoods edhGoods);
    /**
     * 批量修改上架状态
     * @param ids
     * @return
     */
    public Integer editOnsale(@Param("ids") Long[] ids, @Param("onSale") String onSale);
    /**
     * 删除易订货-商品
     *
     * @param id 易订货-商品ID
     * @return 结果
     */
    public int deleteEdhGoodsById(Long id);

    /**
     * 批量删除易订货-商品
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteEdhGoodsByIds(Long[] ids);
    /**
     * 首页商品总览数据
     */
    public Map<String,Object> getProductOverview(Long userId);

    /** 获取有商品的分类 */
    @Select("select id , name label from edh_categories where id in (select distinct categories_id from edh_goods ) and del_flag = 0")
    public List<Map<String,Object>> getCategoriesHasGoods();

    /**获取所有商品id，名称，分类*/
    @Select("select id,title label,categories_id pid from edh_goods where del_flag = 0")
    public List<Map<String,Object>> selectAll();

    /** 获取排期id已经选中的商品 */
    @Select("select goods_id from edh_scheduled_goods where scheduled_id = #{scheduledId}")
    public List<Long> selectGoodsIdByScheduledId(@Param("scheduledId") Long scheduledId);

    /** 根据商品排期来设置可被团长转卖 */
    @Update("UPDATE   edh_goods set resell = 1 WHERE id in (SELECT goods_id from edh_scheduled_goods where scheduled_id  in  (SELECT id from edh_scheduled where NOW() BETWEEN scheduled_start_time and scheduled_end_time))")
    public Integer openResellByScheduled();
    /** 根据商品排期来设置不可被团长转卖 */
    @Update("UPDATE   edh_goods set resell = 0 WHERE id in (SELECT goods_id from edh_scheduled_goods where scheduled_id  not in  (SELECT id from edh_scheduled where NOW() BETWEEN scheduled_start_time and scheduled_end_time))")
    public Integer closeResellByScheduled();

    @Select("select  id ,details from edh_goods")
    List<EdhGoodsDetail> allDetails();

}
